home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1UFJZK5 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.2 KB  |  65 lines

  1. package com.sun.java.swing.border;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.Insets;
  7.  
  8. public class EtchedBorder extends AbstractBorder {
  9.    public static final int RAISED = 0;
  10.    public static final int LOWERED = 1;
  11.    protected int etchType;
  12.    protected Color highlight;
  13.    protected Color shadow;
  14.  
  15.    public EtchedBorder() {
  16.       this(1);
  17.    }
  18.  
  19.    public EtchedBorder(int etchType) {
  20.       this(etchType, (Color)null, (Color)null);
  21.    }
  22.  
  23.    public EtchedBorder(int etchType, Color highlight, Color shadow) {
  24.       this.etchType = etchType;
  25.       this.highlight = highlight;
  26.       this.shadow = shadow;
  27.    }
  28.  
  29.    public EtchedBorder(Color highlight, Color shadow) {
  30.       this(1, highlight, shadow);
  31.    }
  32.  
  33.    public Insets getBorderInsets(Component c) {
  34.       return new Insets(2, 2, 2, 2);
  35.    }
  36.  
  37.    public int getEtchType() {
  38.       return this.etchType;
  39.    }
  40.  
  41.    public Color getHighlightColor(Component c) {
  42.       return this.highlight != null ? this.highlight : c.getBackground().brighter();
  43.    }
  44.  
  45.    public Color getShadowColor(Component c) {
  46.       return this.shadow != null ? this.shadow : c.getBackground().darker();
  47.    }
  48.  
  49.    public boolean isBorderOpaque() {
  50.       return true;
  51.    }
  52.  
  53.    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  54.       g.translate(x, y);
  55.       g.setColor(this.etchType == 1 ? this.getShadowColor(c) : this.getHighlightColor(c));
  56.       g.drawRect(0, 0, width - 2, height - 2);
  57.       g.setColor(this.etchType == 1 ? this.getHighlightColor(c) : this.getShadowColor(c));
  58.       g.drawLine(1, height - 3, 1, 1);
  59.       g.drawLine(1, 1, width - 3, 1);
  60.       g.drawLine(0, height - 1, width - 1, height - 1);
  61.       g.drawLine(width - 1, height - 1, width - 1, 0);
  62.       g.translate(-x, -y);
  63.    }
  64. }
  65.